//
//  tirpViewCell.m
//  YouGoWeGo
//
//  Created by 范业君 on 14-11-25.
//  Copyright (c) 2014年 LiuFei. All rights reserved.
//

#import "tirpViewCell.h"
#import "theTripModel.h"
#import "UIImageView+WebCache.h"

@implementation tirpViewCell


- (void)dealloc
{
    [_tripModel release];
    [_aImage release];
    [_aLabel release];
    [self removeObserver:self forKeyPath:@"tripModel"];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.aImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        //[_aImage setBackgroundColor: [UIColor blueColor]];
        [_aImage.layer setCornerRadius:5];
        [_aImage setClipsToBounds:YES];
        [self.contentView addSubview:_aImage];
        [_aImage release];
        
        
        self.aLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        //[_aLabel setBackgroundColor:[UIColor yellowColor]];
        [_aLabel setNumberOfLines:0];
        [_aLabel setFont:[UIFont systemFontOfSize:11]];
        [self.contentView addSubview:_aLabel];
        [_aLabel release];
        
        [self addObserver:self forKeyPath:@"tripModel" options:NSKeyValueObservingOptionNew context:nil];
    }
    return self;
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"tripModel"]) {
        [self.aLabel setText:self.tripModel.text];
        [self.aImage setImageWithURL:[NSURL URLWithString:self.tripModel.cover]];
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [_aImage setFrame:CGRectMake(10, 10, self.frame.size.width - 20, 200)];
   
 
    [_aLabel setFrame:CGRectMake(_aImage.frame.origin.x, _aImage.frame.size.height + 10, _aImage.frame.size.width, 50)];
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
